package main.od;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class OdTest02 {
    public static void main(String[] args) {
        System.out.println("please input a string that has only a-z/A-Z,-,digital!");
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        int output = getMinInteger(input);
        System.out.println("the min integer is " + output);
    }
    private static int getMinInteger(String str){
        List<Integer> integerList = new ArrayList<>();
        StringBuilder stringBuilder = new StringBuilder();
        boolean isPositive = true;
        int sum = 0;
        char[] chars = str.toCharArray();
        for (int i = 0;i < chars.length;i++){
            char temp = chars[i];
            if ('-' == temp){
                isPositive = false;
                // --
                if (0 == stringBuilder.length() || '-' != stringBuilder.charAt(0)){
                    stringBuilder.append(temp);
                }
            }else if (Character.isDigit(temp)){
                if (!isPositive) {
                    stringBuilder.append(temp);
                }else {
                    integerList.add(Integer.valueOf(Character.toString(temp)));
                }
            }else {
                isPositive = true;
                if (stringBuilder.length() > 1){
                    integerList.add(Integer.valueOf(stringBuilder.toString()));
                    stringBuilder = new StringBuilder();
                }
            }
            // b12-12
            if (i == chars.length - 1 && stringBuilder.length() > 1){
                integerList.add(Integer.valueOf(stringBuilder.toString()));
            }
        }
        return integerList.stream().mapToInt(Integer::intValue).sum();
    }
}
